home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-202.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  41.8 KB  |  1,282 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Sun, 01 Nov 92       Volume 1 : Issue 202
  2.  
  3. Today's Topics:
  4.  
  5.     Help: mounting appleshare volumes
  6.     #pragma parameter in MPW C++
  7.     Berkeley Socket Emulation for MacTCP (possible FAQ)?
  8.     fast serial I/O in Think C with extra hardware?
  9.     Easter was: Re: Algorithm for Day-Of-Week NEEDED
  10.     Help: Sample code wanted
  11.     Random() needs some Thorazine (Help!)
  12.  
  13.  
  14.  
  15. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  16.  
  17. The digest is a collection of article threads from the internet newsgroup
  18. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  19. regularly and want an archive of the discussions.  If you don't know what a
  20. newsgroup is, you probably don't have access to it.  Ask your systems
  21. administrator(s) for details.  (This means you can't post questions to the
  22. digest.)
  23.  
  24. Each issue of the digest contains one or more sets of articles (called
  25. threads), with each set corresponding to a 'discussion' of a particular
  26. subject.  The articles are not edited; all articles included in this digest
  27. are in their original posted form (as received by our news server at
  28. cs.uoregon.edu).  Article threads are not added to the digest until the last
  29. article added to the thread is at least one month old (this is to ensure that
  30. the thread is dead before adding it to the digest).  Article threads that
  31. consist of only one message are generally not included in the digest.
  32.  
  33. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  34. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  35. file /pub/mac/csmp-digest/README before downloading any files.  The most
  36. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  37. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  38. archive has a mail server; send a message with the text '$MACarch help' (no
  39. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  40.  
  41. The digest is also available via email.  Just send a note saying that you
  42. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  43. automatically receive each new issue as it is created.  Sorry, back issues
  44. are not available through the mailing list.
  45.  
  46. Send administrative mail to mkelly@cs.uoregon.edu.
  47.  
  48.  
  49. -------------------------------------------------------
  50.  
  51. From: perrins@vax.oxford.ac.uk
  52. Subject: Help: mounting appleshare volumes
  53. Date: 23 Sep 92 15:28:26 GMT
  54. Organization: Oxford University VAX 6620
  55.  
  56. Help wanted with AppleShare ....
  57.  
  58. Does anyone out there know how to mount an AppleShare volume from within an
  59. application (written in pascal or C). There is a hypercard XCMD which does what
  60. I want (gets the username,password,zonename,servername etc all lined up and
  61. then mounts the volume if it exists).
  62. I need this 'cos I have an application which runs at startup to force a login
  63. to a server, and set the chooser name to the appleshare username, as a way of
  64. validating users on a large network. This relies on the fact that appleshare
  65. offers a login automatically at boot up time if so desired, on our system this
  66. is followed by the startup application. However if the user
  67. logs out by throwing away the server icon another user logging in in the
  68. standard way does not have his chooser name fixed.
  69. Any ideas most welcome...
  70. R.McCleery - dept of zoology oxford uk.
  71.  
  72. +++++++++++++++++++++++++++
  73.  
  74. From: larimer@zeus.cdc.com (Mark D. Larimer)
  75. Date: 27 Sep 92 05:42:34 GMT
  76. Organization: Control Data Systems, Inc.
  77.  
  78. In article <1992Sep23.162826.9004@vax.oxford.ac.uk> ,
  79. perrins@vax.oxford.ac.uk writes:
  80.  
  81. >Does anyone out there know how to mount an AppleShare volume from within
  82. an
  83. >application (written in pascal or C). There is a hypercard XCMD which
  84. does what
  85. >I want (gets the username,password,zonename,servername etc all lined up
  86. and
  87. >then mounts the volume if it exists).
  88. >I need this 'cos I have an application which runs at startup to force a
  89. login
  90. >to a server, and set the chooser name to the appleshare username, as a
  91. way of
  92. >validating users on a large network. This relies on the fact that
  93. appleshare
  94. >offers a login automatically at boot up time if so desired, on our
  95. system this
  96. >is followed by the startup application. However if the user
  97. >logs out by throwing away the server icon another user logging in in the
  98. >standard way does not have his chooser name fixed.
  99. >Any ideas most welcome...
  100.  
  101. I've got pascal code that does this.  System 6 users are required to have
  102. version 3.0 
  103. of the AppleShare rdev (Chooser device) in their System Folder for this
  104. to work, but 
  105. according to Apple itself, without AppleShare 3.0, there is no other way
  106. to do it 
  107. under System 6 other than the XCMD you mentioned above.  System 7 users
  108. will have no 
  109. problem.  Note that the server being mounted doesn't have to be running
  110. AppleShare 3.0; 
  111. only the Mac mounting the server needs to have the AppleShare 3.0
  112. resource.
  113.  
  114. Good luck and let me know how it goes...
  115.  
  116. Mark D. Larimer
  117. (Control Data Systems, Inc.) && (University of Minnesota)
  118. Mark.D.Larimer@zeus.cdc.com
  119.  
  120. {-------------------------------------------------------------------}
  121.     Function Pack (s1,s2,s3,s4,s5,s6 : Str255) : packedType; FORWARD;
  122. {-------------------------------------------------------------------}
  123.  
  124.     { The guts of the proc that mounts a server in either }
  125.     {   System 7 or System 6 with AppleShare 3.0 rdev.    }
  126.     Procedure MountIt;
  127.     
  128.     var    err                    : OSErr;
  129.             errStr            : Str255;
  130.             myBuffer        : AFPVolMountInfo;
  131.             myParamBlock: ParamBlockRec;
  132.  
  133.         begin
  134.             with myBuffer do begin
  135.                 media:='afpm';          { type of volume; four-character code; afpm =
  136. AppleShareMediaType    }
  137.                 flags:=0;               { reserved; must be set to 0    }
  138.                 nbpInterval:=8;         { Name-Binding Protocol (NBP) retry interval    }
  139.                 nbpCount:=3;            { NBP retry count    }
  140.                 uamType:=2;             { user authentication method; 2 = kPassword =
  141. 8-byte password }
  142.                 zoneNameOffset:=24;     { offset from start of record to zone name    }
  143.                 serverNameOffset:=57;   {                             to server name    }
  144.                 volNameOffset:=89;      {                             to volume name 
  145. }
  146.                 userNameOffset:=117;    {                                                            to user name    }
  147.                 userPassWordOffset:=149;{                             to user
  148. password    }
  149.                 volPassWordOffset:=158; {                             to volume
  150. password    }
  151.                 
  152.                 {                                                              user  
  153.     volume  }
  154.                 {              zone name   server        volume     username   pw    
  155.     pw      }
  156.                 afpData:=Pack('ZONE NAME','Cool Server','Volume
  157. I','username','password','password');
  158.                 length:=sizeof(myBuffer);    { length of mounting information    }
  159.             end;
  160.             
  161.             myParamBlock.ioCompletion:=nil;        { proc pointer to execute upon
  162. completion    }
  163.             myParamBlock.ioBuffer:=@myBuffer; { pointer to mounting information
  164. record    }
  165.  
  166.             err:=PBVolumeMount(@myParamBlock);    { mount the volume    }
  167.             if err<>0 then begin
  168.                 NumToString(err,errStr);
  169.                 ParamText('Error during PBVolumeMount',errStr,'','');
  170.                 itemHit:=Alert(idAlert,nil);
  171.             end
  172.             else
  173.                 serverVRefNum:=myParamBlock.ioVRefNum;    { if successful, vol ref num
  174. returned    }
  175.         end;
  176.  
  177. {----------------------------------------------------------------------
  178. - ------}
  179.  
  180.     { Lay the mounting information into the buffer at the proper offset
  181. locations }
  182.     Function Pack(s1,s2,s3,s4,s5,s6:Str255):packedType;
  183.     
  184.     var    i,j        : integer;
  185.             Data    : packedType;
  186.             
  187.         begin
  188.             j:=2;
  189.             Data[1]:=chr(length(s1));
  190.             for i:=1 to length(s1) do begin
  191.                 Data[j]:=s1[i];
  192.                 j:=j+1;
  193.             end;
  194.             
  195.             j:=35;
  196.             Data[34]:=chr(length(s2));
  197.             for i:=1 to length(s2) do begin
  198.                 Data[j]:=s2[i];
  199.                 j:=j+1;
  200.             end;
  201.             
  202.             j:=67;
  203.             Data[66]:=chr(length(s3));
  204.             for i:=1 to length(s3) do begin
  205.                 Data[j]:=s3[i];
  206.                 j:=j+1;
  207.             end;
  208.             
  209.             j:=95;
  210.             Data[94]:=chr(length(s4));
  211.             for i:=1 to length(s4) do begin
  212.                 Data[j]:=s4[i];
  213.                 j:=j+1;
  214.             end;
  215.             
  216.             j:=127;
  217.             Data[126]:=chr(length(s5));
  218.             for i:=1 to length(s5) do begin
  219.                 Data[j]:=s5[i];
  220.                 j:=j+1;
  221.             end;
  222.             
  223.             j:=136;
  224.             Data[135]:=chr(length(s6));
  225.             for i:=1 to length(s6) do begin
  226.                 Data[j]:=s6[i];
  227.                 j:=j+1;
  228.             end;
  229.             
  230.         Pack:=Data;
  231.     end;
  232.  
  233. {--------------------------------------------------------------}
  234.  
  235. +++++++++++++++++++++++++++
  236.  
  237. From: larimer@zeus.cdc.com (Mark D. Larimer)
  238. Date: 27 Sep 92 06:24:08 GMT
  239. Organization: Control Data Systems, Inc.
  240.  
  241. Let me rephrase that...
  242.  
  243. {-------------------------------------------------------------------}
  244.   Function Pack (s1,s2,s3,s4,s5,s6 : Str255) : packedType; FORWARD;
  245. {-------------------------------------------------------------------}
  246.  
  247. { The guts of the proc that mounts a server in either }
  248. {   System 7 or System 6 with AppleShare 3.0 rdev.    }
  249. Procedure MountIt;
  250.   
  251.   var  err         : OSErr;
  252.        errStr      : Str255;
  253.        myBuffer    : AFPVolMountInfo;
  254.        myParamBlock: ParamBlockRec;
  255.  
  256.     begin
  257.       with myBuffer do begin
  258.         media:='afpm'; { type of volume; four-character code; afpm =
  259. AppleShareMediaType  }
  260.         flags:=0; { reserved; must be set to 0  }
  261.         nbpInterval:=8; { Name-Binding Protocol (NBP) retry interval  }
  262.         nbpCount:=3; { NBP retry count  }
  263.         uamType:=2; { user authentication method; 2 = kPassword = 8-byte
  264. password }
  265.         zoneNameOffset:=24; { offset from start of record to zone name  }
  266.         serverNameOffset:=57; { offset to server name  }
  267.         volNameOffset:=89; { offset to volume name   }
  268.         userNameOffset:=117; { offset to user name  }
  269.         userPassWordOffset:=149; { offset to user password  }
  270.         volPassWordOffset:=158; { offset to volume password  }
  271.         
  272.         {                                                             
  273. user       volume  }
  274.         {              zone name   server        volume     username   pw
  275.         pw      }
  276.         afpData:=Pack('ZONE NAME','Cool Server','Volume
  277. I','username','password','password');
  278.         length:=sizeof(myBuffer);  { length of mounting information  }
  279.       end;
  280.       
  281.       myParamBlock.ioCompletion:=nil; { proc pointer to execute upon
  282. completion  }
  283.       myParamBlock.ioBuffer:=@myBuffer; { pointer to mounting information
  284.  record  }
  285.  
  286.       err:=PBVolumeMount(@myParamBlock);  { mount the volume  }
  287.       if err<>0 then begin
  288.         NumToString(err,errStr);
  289.         ParamText('Error during PBVolumeMount',errStr,'','');
  290.         itemHit:=Alert(idAlert,nil);
  291.       end
  292.       else
  293.         serverVRefNum:=myParamBlock.ioVRefNum;  { if successful, vol ref
  294. num returned  }
  295.     end;
  296.  
  297. {----------------------------------------------------------------------
  298. - ------}
  299.  
  300.   { Lay the mounting information into the buffer at the proper offset
  301. locations }
  302.   Function Pack(s1,s2,s3,s4,s5,s6:Str255):packedType;
  303.   
  304.   var  i,j   : integer;
  305.        Data  : packedType;
  306.       
  307.     begin
  308.       j:=2;
  309.       Data[1]:=chr(length(s1));
  310.       for i:=1 to length(s1) do begin
  311.         Data[j]:=s1[i];
  312.         j:=j+1;
  313.       end;
  314.       
  315.       j:=35;
  316.       Data[34]:=chr(length(s2));
  317.       for i:=1 to length(s2) do begin
  318.         Data[j]:=s2[i];
  319.         j:=j+1;
  320.       end;
  321.       
  322.       j:=67;
  323.       Data[66]:=chr(length(s3));
  324.       for i:=1 to length(s3) do begin
  325.         Data[j]:=s3[i];
  326.         j:=j+1;
  327.       end;
  328.       
  329.       j:=95;
  330.       Data[94]:=chr(length(s4));
  331.       for i:=1 to length(s4) do begin
  332.         Data[j]:=s4[i];
  333.         j:=j+1;
  334.       end;
  335.       
  336.       j:=127;
  337.       Data[126]:=chr(length(s5));
  338.       for i:=1 to length(s5) do begin
  339.         Data[j]:=s5[i];
  340.         j:=j+1;
  341.       end;
  342.       
  343.       j:=136;
  344.       Data[135]:=chr(length(s6));
  345.       for i:=1 to length(s6) do begin
  346.         Data[j]:=s6[i];
  347.         j:=j+1;
  348.       end;
  349.       
  350.     Pack:=Data;
  351.   end;
  352.  
  353. {--------------------------------------------------------------}
  354.  
  355. ---------------------------
  356.  
  357. From: liran@bimacs.BITNET (Eshel Liran)
  358. Subject: #pragma parameter in MPW C++
  359. Date: 24 Sep 92 08:46:12 GMT
  360. Organization: Math & CS, BarIlan U, Ramat-Gan, Israel
  361.  
  362. In the AppleShare 3.0 Developers Kit there is a direct assembler function which
  363. comes under the following compiler directive:
  364.  
  365. #pragma parameter __D0 SynchServerDispatch(__A0)
  366.  
  367. It worked fine in THINK C but when I tried to use it in MPW C++ it didn't work.
  368. After viewing the assembly code created by the compiler it seems that it
  369. didn't work because of the #pragma compiler directive.
  370.  
  371. Any solutions ?
  372.  
  373. - ----------------------------------------
  374. Liran Eshel,
  375. Bar-Ilan University, ISRAEL
  376. liran@bimacs.cs.biu.ac.il
  377. - ----------------------------------------
  378.  
  379. +++++++++++++++++++++++++++
  380.  
  381. From: ksand@apple.com (Kent Sandvik)
  382. Date: 26 Sep 92 01:17:09 GMT
  383. Organization: Apple
  384.  
  385. In article <4224@bimacs.BITNET>, liran@bimacs.BITNET (Eshel Liran) wrote:
  386. > In the AppleShare 3.0 Developers Kit there is a direct assembler function which
  387. > comes under the following compiler directive:
  388. > #pragma parameter __D0 SynchServerDispatch(__A0)
  389. > It worked fine in THINK C but when I tried to use it in MPW C++ it didn't work.
  390. > After viewing the assembly code created by the compiler it seems that it
  391. > didn't work because of the #pragma compiler directive.
  392.  
  393. I don't have the kit handy, but I think that the C++ wrappers are 
  394. missing, so the function name is maybe mangled, and the linker does not 
  395. find the right function. Place something like this around the assembler
  396. functions (example stolen from MPW Start.h):
  397.  
  398. #ifdef __cplusplus
  399. extern "C" {
  400. #endif
  401. #pragma parameter GetDefaultStartup(__A0)
  402. pascal void GetDefaultStartup(DefStartPtr paramBlock)
  403.     = 0xA07D; 
  404. #pragma parameter SetDefaultStartup(__A0)
  405. pascal void SetDefaultStartup(DefStartPtr paramBlock)
  406.     = 0xA07E; 
  407. ...
  408. pascal void SetTimeout(short count); 
  409. pascal void GetTimeout(short *count); 
  410. #ifdef __cplusplus
  411. }
  412. #endif
  413.  
  414. Cheers,
  415. Kent/DTS
  416. - -------------------
  417. Kent Sandvik (UUCP: ....!apple!ksand; INTERNET: ksand@apple.com)
  418. DISCLAIMER: Private activities on the Net.
  419.  
  420. ---------------------------
  421.  
  422. From: dank@blacks.jpl.nasa.gov (Daniel R. Kegel)
  423. Subject: Berkeley Socket Emulation for MacTCP (possible FAQ)?
  424. Organization: Image Analysis Systems Group, JPL
  425. Date: Thu, 24 Sep 1992 15:53:26 GMT
  426.  
  427. Hi,
  428. I'm looking for a C library that makes MacTCP look like Berkeley Sockets.
  429. I hear that MIT wrote something like this, and have heard rumors of
  430. other packages.  Has anybody heard of such a thing?
  431. - - Dan Kegel (dank@blacks.jpl.nasa.gov)
  432.  
  433. +++++++++++++++++++++++++++
  434.  
  435. From: ejohnson@void.ncsa.uiuc.edu (Eric E. Johnson)
  436. Date: 24 Sep 92 17:01:11 GMT
  437. Organization: University of Illinois at Urbana
  438.  
  439. dank@blacks.jpl.nasa.gov (Daniel R. Kegel) writes:
  440.  
  441. >I'm looking for a C library that makes MacTCP look like Berkeley Sockets.
  442. >I hear that MIT wrote something like this, and have heard rumors of
  443. >other packages.  Has anybody heard of such a thing?
  444.  
  445. There are two libraries that I know of.
  446.  
  447. The first one is a sockets implementation that's available somewhere
  448. on NCSA's ftp machine, ftp.ncsa.uiuc.edu.  Its not officially part of
  449. NCSA's software, so it is unsupported.
  450.  
  451. The second package is one that Igor Livshits, John Newlin and I worked
  452. on; it is *not* sockets.  But, it does demonstrate how to use
  453. MacTCP.  Its a class library for Think C 5.0, and demonstrates how to
  454. use a majority of the functions.  You can find that at ftp.brown.edu,
  455. in pub/tcl/contributors/University_of_Illinois.
  456.  
  457. Eric
  458.  
  459. +++++++++++++++++++++++++++
  460.  
  461. From: ldh@svl.cdc.com (Lawrence D. Hare)
  462. Date: 28 Sep 92 16:38:49 GMT
  463. Organization: Control Data Systems
  464.  
  465. In article <ejohnson.717354071@void> Eric E. Johnson,
  466. ejohnson@void.ncsa.uiuc.edu writes:
  467. >>I'm looking for a C library that makes MacTCP look like Berkeley
  468. Sockets.
  469. >>I hear that MIT wrote something like this, and have heard rumors of
  470. >>other packages.  Has anybody heard of such a thing?
  471.  
  472. BSD sockets for MPW (and maybe in Think C?) : ftp to
  473. madhaus.utcs.toronto.ca
  474.  
  475. Socket library for MacTCP based on BSD: ftp to net-dist.mit.edu and get
  476. the
  477. file jon/bsd-mac-compat.sit.hqx.  Problems to jon rochlis (jon@mit.edu)
  478.  
  479. This information originally supplied by sylviae@uga.cc.uga.edu.
  480.  
  481. Hope this helps
  482. - --
  483. Lawrence D. Hare
  484.  
  485. ---------------------------
  486.  
  487. From: hase@netmbx.netmbx.de (Hartmut Semken)
  488. Subject: fast serial I/O in Think C with extra hardware?
  489. Organization: netmbx, Berlin, Germany
  490. Date: Thu, 24 Sep 1992 16:20:19 GMT
  491.  
  492. Hello out there.
  493.  
  494. Sure it is possible to run the Macs modem port at up to 57600 Baud.
  495. But what if You want (need) to be faster than that? (LocalTalk runs
  496. faster, doen't it?)
  497.  
  498. Has anyone tried to feed the ACIA with an external clock? How do I set
  499. up the port to accept an external clock.
  500.  
  501. And how do I run the port in synchronous mode? I am told this beiing
  502. impossible on IIfx and Q900/Q950. If that is right, I'll probably need
  503. an external clock.
  504. Has anyone already built an parallel to serial converter running fast?
  505.  
  506. thanks
  507.  
  508. hase
  509. - -- 
  510. hase
  511. Hartmut Semken, Lupsteiner Weg 67, 1000 Berlin 37     hase@netmbx.netmbx.de
  512. " I liked ZORK. I loved THE PAWN, but then I needed
  513.   an adult adventure. I bought UNIX.
  514.  
  515. +++++++++++++++++++++++++++
  516.  
  517. From: thepope@bigboy (Michael Kohne)
  518. Date: 25 Sep 92 23:14:11 GMT
  519. Organization: Temple University
  520.  
  521. hase@netmbx.netmbx.de (Hartmut Semken) writes:
  522. : Hello out there.
  523. : Sure it is possible to run the Macs modem port at up to 57600 Baud.
  524. : But what if You want (need) to be faster than that? (LocalTalk runs
  525. : faster, doen't it?)
  526. : Has anyone tried to feed the ACIA with an external clock? How do I set
  527. : up the port to accept an external clock.
  528. : And how do I run the port in synchronous mode? I am told this beiing
  529. : impossible on IIfx and Q900/Q950. If that is right, I'll probably need
  530. : an external clock.
  531. : Has anyone already built an parallel to serial converter running fast?
  532. : thanks
  533. : hase
  534. : Hartmut Semken, Lupsteiner Weg 67, 1000 Berlin 37     hase@netmbx.netmbx.de
  535.  
  536. Well, the Serial Chip on the Mac is the Zilog Z8530 SCC Serial Communications
  537. Controller. Find someone with Zilog Databooks, and photocopy the relevant 
  538. pages. This will (after some deciphering) tell you how to do what you want.
  539.  
  540. As for the IIfx: This sort of thing will be harder, if at all possible on the
  541. IIfx(and on some of the newer machines) because there is an IO Processor
  542. inbetween the 680x0 and the SCC. 
  543.  
  544. Have fun.
  545.  
  546. Michael Kohne
  547. "Pope" Q.E.D
  548. House of the Techno-Discordians, Aquatic Amusements Division.
  549.  
  550. P.S. could the original poster send me e-mail if you see this? There
  551. has been some trouble posting from this machine in the past...
  552.  
  553. thepope@bigboy.cis.temple.edu
  554.  
  555. +++++++++++++++++++++++++++
  556.  
  557. From: bwilliam@iat.holonet.net (Bill Williams)
  558. Organization: HoloNet (BBS: 510-704-1058)
  559. Date: Tue, 29 Sep 1992 06:06:26 GMT
  560.  
  561. I (mostly a friend though) have hacked the serial driver to halve the
  562. sample clock rate in the driver so that serial speeds double that of 57600
  563. baud are available. In fact a loop cable linking bothe ports at 115,000
  564. baud in and out at the same time on a standard IIci showed not problems
  565. sending Zmodem protocol files.
  566.  
  567. On sad side effect:
  568.  
  569. Interrupts occured so frequently using both ports at this speed that
  570. TickCount barely ever advanced!!!!!!!!!!!!!!!!!!!!
  571.  
  572. The chip could, not too safely, be halved again to go double the 115,000
  573. baud but everyone I know only needs to go only 115,000 baud to support our
  574. Telebit Worldblazer modems.
  575.  
  576.  
  577. You'll figure it out.
  578.  
  579. (Check dartmouth LocalTalk/serial source from old Doctor dobbs, check MIDI
  580. serial port stuff from various mactutors, get the zilog docs, get a
  581. debugger/dissassembler.
  582.  
  583.  
  584. 115,000 baud is potentially quite simple.
  585.  
  586. Bill Williams
  587.  
  588.  
  589. ---------------------------
  590.  
  591. From: dm@stekt2.oulu.fi (Hannu Helminen)
  592. Subject: Easter was: Re: Algorithm for Day-Of-Week NEEDED
  593. Date: 24 Sep 92 20:06:00 GMT
  594. Organization: University of Oulu, Dept. of EE, Finland
  595.  
  596.  
  597. Does anyone have working C-code to determine when it is Easter in a
  598. given year? It would be handy since I am currently writing a calendar
  599. utility in C. Pointers to such code would also be appreciated.
  600.  
  601. Thanks in advance.
  602. - --
  603.  
  604.    _| _ _    Hannu    dm@stekt.oulu.fi    // Does anybody else in here
  605.   (_|| | )  Helminen dm@phoenix.oulu.fi \X/ feel the way I do?
  606.  
  607. +++++++++++++++++++++++++++
  608.  
  609. From: ebergman@nyx.cs.du.edu (Eric Bergman-Terrell)
  610. Date: 25 Sep 92 13:55:56 GMT
  611. Organization: Nyx, Public Access Unix at U. of Denver Math/CS dept.
  612.  
  613. In article <DM.92Sep24220600@stekt2.oulu.fi> dm@stekt2.oulu.fi (Hannu Helminen) writes:
  614. >
  615. >Does anyone have working C-code to determine when it is Easter in a
  616. >given year? It would be handy since I am currently writing a calendar
  617. >utility in C. Pointers to such code would also be appreciated.
  618. >
  619. >Thanks in advance.
  620. >--
  621. >
  622. >   _| _ _    Hannu    dm@stekt.oulu.fi    // Does anybody else in here
  623. >  (_|| | )  Helminen dm@phoenix.oulu.fi \X/ feel the way I do?
  624.  
  625.  
  626. See "Date Management", Eric Bergman-Terrell in Computer Language, Dec. 90 or
  627.  
  628. Practical Astronomy with your Calculator, Peter Duffett-Smith, Oxford U. Press
  629.  
  630. or
  631.  
  632. Astronomical Formulae for Calculators, Jean Meeus, Willman-Bell, Inc.
  633.  
  634. Terrell
  635.  
  636. +++++++++++++++++++++++++++
  637.  
  638. From: karl@ima.isc.com (Karl Heuer)
  639. Date: 25 Sep 92 21:41:43 GMT
  640. Organization: Interactive Systems, Cambridge, MA 02138-5302
  641.  
  642. In article <DM.92Sep24220600@stekt2.oulu.fi> dm@stekt2.oulu.fi (Hannu Helminen) writes:
  643. >Does anyone have working C-code to determine when it is Easter in a
  644. >given year?
  645.  
  646. /*
  647.  * Table of Easter, 1970-2000; day in March (April if >31).
  648.  */
  649. int eastertab[] = {
  650.     29, 42, 33, 53, 45, 30, 49, 41, 26, 46, 37, 50, 42, 34, 53, 38, 30, 50,
  651.     34, 26, 46, 31, 50, 42, 34, 47, 38, 30, 43, 35, 54,
  652. };
  653.  
  654. +++++++++++++++++++++++++++
  655.  
  656. From: db21@cbnewsc.cb.att.com (david.beyerl)
  657. Organization: AT&T
  658. Date: Sat, 26 Sep 1992 11:23:47 GMT
  659.  
  660. In article <DM.92Sep24220600@stekt2.oulu.fi>, dm@stekt2.oulu.fi (Hannu Helminen) writes:
  661. > Does anyone have working C-code to determine when it is Easter in a
  662. > given year? It would be handy since I am currently writing a calendar
  663. > utility in C. Pointers to such code would also be appreciated.
  664.     An algorithm for the date of Easter is presented on pages
  665. 155-156 in "The Art of Computer Programming, Fundamental Algorithms,
  666. Volume 1, by Knuth.  Below is C-source I obtained from someone on the
  667. net.
  668.  
  669.                         Dave Beyerl
  670.                         att!ihlpm!db21
  671. - ---------------------------------------------------------------------
  672. >From att!world.std.com!geoff Thu Jan 09 12:31:28 0500 1992
  673. Subject: Re: Easter Sunday algorythm 
  674.  
  675. Here you go; enjoy.
  676.  
  677. # To unbundle, sh this file
  678. echo easter.c 1>&2
  679. sed 's/^X//' >easter.c <<'!'
  680. X/*
  681. X * easter - compute date of easter
  682. X *    see The Art of Computer Programming, Vol. 1, pp. 155-6.
  683. X */
  684.  
  685. X# include <stdio.h>
  686. X# include <time.h>
  687. X# include <sys/types.h>
  688.  
  689. X# define CENTURY 100
  690. X# define LEAP 4
  691. X# define WEEK 7
  692. X# define MARCH_DAYS 31
  693. X# define APRIL 3
  694. X# define METONIC 19
  695. X# define BASEYEAR 1900    /* add to localtime(t)->tm_year */
  696. X# define GREGORY 1582    /* start of gregorian calendar */
  697.  
  698. main(argc, argv)
  699. char ** argv;
  700. X{
  701. X    if (argc > 2)
  702. X        fprintf(stderr, "usage: easter [year]\n");
  703. X    else if (argc == 2)
  704. X        easter(atoi(argv[1]));
  705. X    else
  706. X        easter(this_year());
  707. X    exit(0);
  708. X}
  709.  
  710. this_year()
  711. X{
  712. X    register struct tm * lp;
  713. X    time_t t;
  714. X    extern struct tm * localtime();
  715. X    extern time_t time();
  716.  
  717. X    t = time(&t);
  718. X    lp = localtime(&t);
  719. X    if (lp->tm_mon > APRIL)
  720. X        lp->tm_year++;
  721. X    return(lp->tm_year + BASEYEAR);
  722. X}
  723.  
  724. easter(year)
  725. register int year;
  726. X{
  727. X    register int epact, fullmoon;
  728. X    int golden, century, noleap;
  729.  
  730. X    if (year < GREGORY) {
  731. X        printf("%d: before Gregory\n", year);
  732. X        return;
  733. X    }
  734. X    golden = year % METONIC + 1;
  735. X    century = year / CENTURY + 1;
  736. X    noleap = 3 * century / LEAP - 12;
  737. X    epact = (11 * golden + 20 +
  738. X        (8 * century + 5) / 25 - 5    /* moon orbit correction */
  739. X        - noleap) % 30;
  740. X    if (epact < 0)
  741. X        epact += 30;    /* make remainder positive */
  742. X    if (epact == 25 && golden > 11 || epact == 24)
  743. X        ++epact;
  744. X    fullmoon = 44 - epact;
  745. X    if (fullmoon < 21)
  746. X        fullmoon += 30;
  747. X    fullmoon += WEEK - (
  748. X        (int)(5L * year / LEAP) - noleap - 10
  749. X        + fullmoon) % WEEK;    /* advance to Sunday */
  750. X    if (fullmoon > MARCH_DAYS)
  751. X        printf("%d April", fullmoon - MARCH_DAYS);
  752. X    else
  753. X        printf("%d March", fullmoon);
  754. X    printf(" %d\n", year);
  755. X}
  756. !
  757.  
  758.  
  759. ---------------------------
  760.  
  761. From: tbl@rock.concert.net (Ted Lowery)
  762. Subject: Help: Sample code wanted
  763. Date: 24 Sep 92 17:14:11 GMT
  764. Organization: MacSolutions
  765.  
  766. Hi All-
  767.  
  768. I posted a sample code request about a week ago, and really did not get any
  769. decent responses.  So I am going to try again.
  770.  
  771. I have been struggling with some code that you might be able to help me with.
  772. What I am trying to do is patch to the shutdown command and perform some
  773. special clean-up everytime at shutdown.  I have an application which will do 
  774. exactly what I want, and I have been successfully able to make it into an init 
  775. that will do it while the init is loading.
  776.  
  777. But what I can't figure out how to do is get it to load and stay around until 
  778. shutdown is invoked.  I have installed entrypoint as a shutdown procptr, but 
  779. it crashes every time.  I suspect my code is disappearing right after the init 
  780. finishes loading.  I got the doohicky sample code off the developer disk, but 
  781. so far haven't been able to make heads or tails of it.
  782.  
  783. I see tons of shareware and freeware stuff that does this kind of thing all 
  784. the time.  I am sure some of you are doing it with think C 5.0.  Would someone 
  785. PLEASE send me some source code which will explain the proper methods to me.  
  786. Not only code, but directions on how to set up the project properly and any 
  787. other useful information you might have.  I know that some of you must have 
  788. been frustrated trying to do this yourself.
  789.  
  790. I cannot really offer anything in return for the sources, except the 
  791. possibility that I might write something really cool and useful someday!  
  792. I understand how precious some of you feel your code is, but isn't this sort 
  793. of thing one of the main reasons the net is here?
  794.  
  795. Please don't write me back and say something like "look on sumex or 
  796. ftp.apple.com.  there's lots of good stuff there!".  I have already looked,
  797. but nothing seems to jump out at me as to be the solution.  And at 2400bps, 
  798. I really don't want to download the entire archives hunting for that 
  799. preverbial needle in the haystack.
  800.  
  801. Also, please don't write me back saying to check out doohickey or TN256.  
  802. I have again looked at these, and so far the lightbulb is still off.
  803.  
  804. What I really want is an example.  I have no plans of stealing your code 
  805. and trying to re-sell it.  I dont' charge for my shareware anyhow.  (check 
  806. out random art or mines, but my creation and both freeware.)
  807.  
  808. If you have any code you would like to pass along, or know the exact location 
  809. of any (server, filename, path and all), please e-mail me back.
  810.  
  811. Thanks in advance for any help you can give me.
  812.  
  813. Ted.
  814.  
  815. +----------------------------+----------------------------+
  816. |  Ted Lowery                |              MacSolutions  |
  817. |  tbl@rock.concert.net      |              PO Box 30051  |
  818. |  CIS: 76350,2613           |        Raleigh, NC  27622  |
  819. +----------------------------+----------------------------+
  820. |  Seen recently on a restroom wall next to the automatic |
  821. |  hand dryer...                                          |
  822. |    "Push button for a message from your congressman."   |
  823. +---------------------------------------------------------+
  824.  
  825. +++++++++++++++++++++++++++
  826.  
  827. From: veloso@husc9.harvard.edu (Manuel Veloso)
  828. Date: 25 Sep 92 15:46:55 GMT
  829. Organization: Harvard University
  830.  
  831. In article <1992Sep24.171411.7499@nrtpa038.bnr.ca> Ted Lowery,
  832. tbl@rock.concert.net writes:
  833. >If you have any code you would like to pass along, or know the exact
  834. location 
  835. >of any (server, filename, path and all), please e-mail me back.
  836.  
  837. Hi there,
  838.  
  839. what you've got to do is, when your init is run,
  840. 1) do any initializations which change actual code data,
  841. 2) create a new ptr in the system heap,
  842. 3) copy your init (shutdownproc, in this case) into the new pointer.
  843. 4) now install your shutdown proc (ShutDwnInstall)
  844.  
  845. why?
  846.  
  847. because your resource/init goes away after the INIT31 closes your 
  848. resource file (&demolishes the heap you're in). Luckily, I've just
  849. finishing a shutdownproc init (how 'bout that), and the code (in
  850. MPW assembler) is:
  851.  
  852. INITInstall        PROC    EXPORT
  853.                 IMPORT    myInit:CODE
  854.                 IMPORT    myInstall:CODE            ; installs the shutdownproc
  855.                 IMPORT    getAlias:CODE
  856. FirstResByte    EQU        myProc                    ; first 'real' procedure associated with
  857. your init
  858.                 
  859. start            movem.l    a0-a7/d0-d7, -(sp)        ; save the registers!
  860.                 move.l    TheZone, a3                ; save the original zone
  861.                 move.l    SysZone, TheZone        ; new systemzone.
  862.                 
  863.                 lea        start, a0                ; get loc of init
  864.                 _RecoverHandle                    ; find the handle
  865.                 _GetHandleSize                    ; how big? in D0
  866.                 
  867.                 lea        FirstResByte,A0            ; first byte of resident code
  868.                 lea        start,A1                ; first byte of header
  869.                 sub.l    A1,A0                    ; size of header to be discarded
  870.                 sub.l    A0,D0                    ; remove header from INIT to get resident size
  871.                 move.l    D0,D1                    ; save size later for BlockMove
  872.                 _NewPtr ,sys,clear                ; make the resident block in System heap
  873.                 tst.w    d0                        ; check for getting an error
  874.                 bne.s    exit                    ; got one, blow out
  875.                 
  876.                 move.l    A0,A1                    ; save new location for _BlockMove
  877.  
  878.                 lea        FirstResByte,A0            ; set A0 to source
  879.                 move.l    D1,D0                    ; set D0 to size
  880.                 _BlockMove
  881.  
  882.                 bsr        myInstall                ; installation routine
  883.                 
  884. exit            move.l    a3, TheZone                ; restore original zone
  885.                 movem.l    (sp)+, a0-a7/d0-d7        ; restore the registers
  886.                 rts                                ; return to INIT 31
  887.                 ENDP
  888.                 END
  889.                 
  890. NOTE:    this routine should be linked in FIRST, and the 'real' code should
  891. be linked in afterwords.
  892.         FirstResByte should be tqual to the first procedure following this
  893. routine.
  894.     
  895. Basically, this code is apple's installation code for their jGNEFilter...
  896.  
  897. Manuel
  898.  
  899. +++++++++++++++++++++++++++
  900.  
  901. From: veloso@husc9.harvard.edu (Manuel Veloso)
  902. Date: 26 Sep 92 16:13:25 GMT
  903. Organization: Harvard University
  904.  
  905. In article <1992Sep25.114657.15843@husc3.harvard.edu> Manuel Veloso,
  906. veloso@husc9.harvard.edu writes:
  907. >Basically, this code is apple's installation code for their jGNEFilter...
  908.  
  909. Whoops! Sorry, but I forgot: the bsr myInstall has to be the myInstall in
  910. the
  911. new, allocated ptr so that, when you call shutdwninstall, the sdprocptr
  912. points
  913. to the proc in the ptr, not to some random hunk of memory where the init
  914. resource
  915. used to be.
  916.  
  917. Also, I haven't really tried this, but it seems that you could call a
  918. detachresource
  919. on yourself, so you wouldn't be purged out.
  920.  
  921. 'luck,
  922. Manuel
  923.  
  924. +++++++++++++++++++++++++++
  925.  
  926. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  927. Date: 29 Sep 92 03:12:26 GMT
  928. Organization: NCRPDA, Curtin University
  929.  
  930. In article <1992Sep25.114657.15843@husc3.harvard.edu>, Manuel Veloso
  931. <veloso@husc9.harvard.edu> wrote:
  932. > In article <1992Sep24.171411.7499@nrtpa038.bnr.ca> Ted Lowery,
  933. > tbl@rock.concert.net writes:
  934. > >If you have any code you would like to pass along, or know the exact
  935. > location 
  936. > >of any (server, filename, path and all), please e-mail me back.
  937.  
  938. > what you've got to do is, when your init is run,
  939. > 1) do any initializations which change actual code data,
  940. > 2) create a new ptr in the system heap,
  941. > 3) copy your init (shutdownproc, in this case) into the new pointer.
  942. > 4) now install your shutdown proc (ShutDwnInstall)
  943.  
  944. > because your resource/init goes away after the INIT31 closes your 
  945. > resource file (&demolishes the heap you're in). 
  946.  
  947. An alternative that is often used is to mark your INIT resource as System
  948. Heap and Locked, and then you just need to detach the resource before
  949. INIT31 gets a chance to close your res file.  So the only tricky bit is how
  950. to get your address, which is conviniently placed in the ToolScratch
  951. global.
  952.  
  953. Handle me;
  954.  
  955. me = RecoverHandle(ToolScratch);
  956. DetachResource(me);
  957.  
  958. (you could add an HLock(me) in, but if the resource bits aren't set to
  959. system heap its going to fail anyway when INIT31 trashes the current
  960. "application" heap, so basically, make sure the resource bits are set
  961. correctly!)
  962.  
  963. Have fun all,
  964.    Peter.
  965.  
  966. _______________________________________________________________________
  967. Peter N Lewis, NCRPDA, Curtin University       peter@cujo.curtin.edu.au
  968. GPO Box U1987, Perth WA 6001, AUSTRALIA             FAX: +61 9 367 8141
  969.  
  970. ---------------------------
  971.  
  972. From: rpoldrac@s.psych.uiuc.edu (Russ Poldrack)
  973. Subject: Random() needs some Thorazine (Help!)
  974. Date: 24 Sep 92 22:35:24 GMT
  975. Organization: UIUC Department of Psychology
  976.  
  977. I'm trying to get a simple set of random numbers in THINK C.  I set
  978. randSeed using GetDateTime(&randSeed), call Random(), and then assign
  979. the value of randSeed to a long int variable, as suggested here
  980. before.  When I run this under the Debugger it seems to work fine,
  981. giving a sequence of random numbers.  However, when I run it without
  982. the debugger or as an application it spits out the same number after
  983. every call to RAndom(), i.e. the value of randSeed is not changed by
  984. the call.  Am I at fault here or should I just shoot my computer and
  985. become a member of the clergy?
  986.  
  987. Russ 
  988. rpoldrac@psych.uiuc.edu
  989.  
  990. +++++++++++++++++++++++++++
  991.  
  992. From: rbarris@orion.oac.uci.edu (Robert C. Barris)
  993. Date: 25 Sep 92 05:11:52 GMT
  994. Organization: University of California, Irvine
  995.  
  996. In article <Bv3tF1.JvL@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
  997. >I'm trying to get a simple set of random numbers in THINK C.  I set
  998. >randSeed using GetDateTime(&randSeed), call Random(), and then assign
  999. >the value of randSeed to a long int variable, as suggested here
  1000. >before.  When I run this under the Debugger it seems to work fine,
  1001. >giving a sequence of random numbers.  However, when I run it without
  1002. >the debugger or as an application it spits out the same number after
  1003. >every call to RAndom(), i.e. the value of randSeed is not changed by
  1004. >the call.  Am I at fault here or should I just shoot my computer and
  1005. >become a member of the clergy?
  1006. >
  1007. >Russ 
  1008. >rpoldrac@psych.uiuc.edu
  1009.  
  1010. Did you call InitGraf? It's necessary.
  1011.  
  1012. +++++++++++++++++++++++++++
  1013.  
  1014. From: putnam@ux2.cso.uiuc.edu (Daniel E. Putnam - Invoice)
  1015. Date: 25 Sep 92 11:32:59 GMT
  1016. Organization: University of Illinois at Urbana
  1017.  
  1018. rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
  1019.  
  1020. >I'm trying to get a simple set of random numbers in THINK C.  I set
  1021. >randSeed using GetDateTime(&randSeed), call Random(), and then assign
  1022. >the value of randSeed to a long int variable, as suggested here
  1023. >before.  When I run this under the Debugger it seems to work fine,
  1024. >giving a sequence of random numbers.  However, when I run it without
  1025. >the debugger or as an application it spits out the same number after
  1026. >every call to RAndom(), i.e. the value of randSeed is not changed by
  1027. >the call.  Am I at fault here or should I just shoot my computer and
  1028. >become a member of the clergy?
  1029.  
  1030. >Russ 
  1031. >rpoldrac@psych.uiuc.edu
  1032.  
  1033. I'll bet you are using the consoles that come with THINK C.  The reason
  1034. for the failure is that THINK C calls InitGraf on its own private quickdraw
  1035. data structures.
  1036.  
  1037. You can try calling InitGraf on your own, but Inside MAC warns that you must
  1038. call InitGraf once and only once.
  1039.  
  1040. When I looked at this problem, it looked like THINK C was setting randSeed
  1041. as an offset from A5, but Random() was looking for randSeed at A0 - 0x7E.
  1042. Without calling InitGraf(), the two addresses didn't turn out to be the same.
  1043.  
  1044. Maybe you can write an asm that directly sets A0 - 7E.  Its either that, or
  1045. do without THINK C consoles, or risk calling InitGraf twice, or use the srand()
  1046. and rand() that come with the THINK C libraries.
  1047.  
  1048. +++++++++++++++++++++++++++
  1049.  
  1050. From: manutter@grove.iup.edu (M. Nutter)
  1051. Date: 25 Sep 92 12:37:07 GMT
  1052. Organization: iup
  1053.  
  1054. In article <Bv4tF1.I8G@news.cso.uiuc.edu> Daniel E. Putnam - Invoice,
  1055. putnam@ux2.cso.uiuc.edu writes:
  1056. >rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
  1057. >
  1058. >>I'm trying to get a simple set of random numbers in THINK C.  I set
  1059. >>randSeed using GetDateTime(&randSeed), call Random(), and then assign
  1060. >>the value of randSeed to a long int variable, as suggested here
  1061. >>before.  When I run this under the Debugger it seems to work fine,
  1062. >>giving a sequence of random numbers.  However, when I run it without
  1063. >>the debugger or as an application it spits out the same number after
  1064. >>every call to RAndom(), i.e. the value of randSeed is not changed by
  1065. >>the call.  Am I at fault here or should I just shoot my computer and
  1066. >>become a member of the clergy?
  1067. >
  1068. >>Russ 
  1069. >>rpoldrac@psych.uiuc.edu
  1070. >
  1071. >I'll bet you are using the consoles that come with THINK C.  The reason
  1072. >for the failure is that THINK C calls InitGraf on its own private
  1073. quickdraw
  1074. >data structures.
  1075. >
  1076. >You can try calling InitGraf on your own, but Inside MAC warns that you
  1077. must
  1078. >call InitGraf once and only once.
  1079. >
  1080. >When I looked at this problem, it looked like THINK C was setting
  1081. randSeed
  1082. >as an offset from A5, but Random() was looking for randSeed at A0 - 0x7E.
  1083. >Without calling InitGraf(), the two addresses didn't turn out to be the
  1084. same.
  1085. >
  1086. >Maybe you can write an asm that directly sets A0 - 7E.  Its either that,
  1087. or
  1088. >do without THINK C consoles, or risk calling InitGraf twice, or use the
  1089. srand()
  1090. >and rand() that come with the THINK C libraries.
  1091.  
  1092. No need to get so complicated:  just make sure you set randSeed AFTER
  1093. you open your first window or console.
  1094.  
  1095. Also, I wouldn't worry about calling InitGraf twice.  I routinely open
  1096. console windows after doing my own Toolbox initializations and haven't had
  1097. any problems.
  1098.  
  1099. +------------------------------------+
  1100. | Mark Nutter                        |
  1101. | manutter@grove.iup.edu             |
  1102. +------------------------------------+
  1103. | Apple Support Manager              |
  1104. | Indiana University of Pennsylvania |
  1105. | G-4 Stright, Indiana, PA 15705     |
  1106. +------------------------------------+
  1107. | Bonus question:  Which of these    |
  1108. |   two statements is correct?       |
  1109. |     A) Statement "B" is false.     |
  1110. |     B) Statement "A" is true.      |
  1111. +------------------------------------+
  1112.  
  1113. +++++++++++++++++++++++++++
  1114.  
  1115. From: fry@zariski.harvard.edu (David Fry)
  1116. Date: 25 Sep 92 17:24:48 EDT
  1117. Organization: Harvard Math Department
  1118.  
  1119. In article <2AC29F98.4352@news.service.uci.edu> rbarris@orion.oac.uci.edu (Robert C. Barris) writes:
  1120. >In article <Bv3tF1.JvL@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
  1121. >>I'm trying to get a simple set of random numbers in THINK C.  I set
  1122. >>randSeed using GetDateTime(&randSeed), call Random(), and then assign
  1123. >>the value of randSeed to a long int variable, as suggested here
  1124. >>before.  When I run this under the Debugger it seems to work fine,
  1125. >>giving a sequence of random numbers.  However, when I run it without
  1126. >>the debugger or as an application it spits out the same number after
  1127. >>every call to RAndom(), i.e. the value of randSeed is not changed by
  1128. >>the call.  Am I at fault here or should I just shoot my computer and
  1129. >>become a member of the clergy?
  1130. >>
  1131. >>Russ 
  1132. >>rpoldrac@psych.uiuc.edu
  1133. >
  1134. >Did you call InitGraf? It's necessary.
  1135.  
  1136. If he hasn't called InitGraf and his program even runs, presumably
  1137. he's using the ANSI library. In this case don't call InitGraf because
  1138. it will confuse things, but call printf("\n") or some other routine
  1139. to trigger ANSI's own initialization procedure. Be sure to do this
  1140. before making any refernce to randSeed or calling Random().
  1141.  
  1142. David Fry                                  fry@math.harvard.edu
  1143. Division of Applied Sciences               fry@huma1.bitnet
  1144. Harvard University                      ...!harvard!huma1!fry
  1145. Cambridge, MA  02138            
  1146.  
  1147. +++++++++++++++++++++++++++
  1148.  
  1149. From: putnam@ux2.cso.uiuc.edu (Daniel E. Putnam - Invoice)
  1150. Organization: University of Illinois at Urbana
  1151. Date: Sat, 26 Sep 1992 14:30:58 GMT
  1152.  
  1153. M. Nutter <manutter@grove.iup.edu> writes:
  1154.  
  1155. >No need to get so complicated:  just make sure you set randSeed AFTER
  1156. >you open your first window or console.
  1157.  
  1158. Not so!  The following program does not correctly generate new random numbers:
  1159.  
  1160.     #include <console.h>
  1161.     
  1162.     extern long randSeed;
  1163.     main()
  1164.     {
  1165.         printf("Hello World\n");
  1166.         GetDateTime(&randSeed);
  1167.         printf("%d\n", Random());
  1168.     }
  1169.  
  1170. Calling InitGraf(&thePort) after the first printf() seems to work despite
  1171. the warning in "Inside MAC".  The first call to printf() already causes
  1172. the console library to initialize itself, including a call to InitGraf().
  1173.  
  1174. The following asm hack also works if you put it in after setting randSeed.
  1175.  
  1176.     asm
  1177.     {
  1178.         MOVEA.L (A5), A0
  1179.         MOVE.L randSeed, -0x7E(A0)
  1180.     };
  1181.  
  1182. The "MOVEA.L (A5), A0" instruction is exactly what Random() does before
  1183. accessing A0 - 7E to get the value of randSeed.  The two instructions
  1184. above just put the value of randSeed where Random() expects to find it.
  1185.  
  1186. None of this seems particularly satisfactory.  If making the second call
  1187. to InitGraf() doesn't create havoc, I guess its OK.
  1188.  
  1189. +++++++++++++++++++++++++++
  1190.  
  1191. From: manutter@grove.iup.edu (M. Nutter)
  1192. Date: 29 Sep 92 11:54:10 GMT
  1193. Organization: iup
  1194.  
  1195. In article <Bv6wBn.5pF@news.cso.uiuc.edu> Daniel E. Putnam - Invoice,
  1196. putnam@ux2.cso.uiuc.edu writes:
  1197. >M. Nutter <manutter@grove.iup.edu> writes:
  1198. >
  1199. >>No need to get so complicated:  just make sure you set randSeed AFTER
  1200. >>you open your first window or console.
  1201. >
  1202. >Not so!  The following program does not correctly generate new random 
  1203. >numbers:
  1204. >
  1205. >    #include <console.h>
  1206. >    
  1207. >    extern long randSeed;
  1208. >    main()
  1209. >    {
  1210. >        printf("Hello World\n");
  1211. >        GetDateTime(&randSeed);
  1212. >        printf("%d\n", Random());
  1213. >    }
  1214. >
  1215. > [other stuff deleted]
  1216.  
  1217. Hmm, this is interesting.  The above code does indeed generate the
  1218. same "random" number every time it is run.  What is more interesting,
  1219. the following code also generates the same number every time, but the
  1220. number is different than the number generated by the above code:
  1221.  
  1222. #include <stdio.h>
  1223.  
  1224. main()
  1225. {
  1226.   long dummy;
  1227.     
  1228.   printf("\n");
  1229.   GetDateTime(&dummy);
  1230.   randSeed = dummy;
  1231.   printf("%ld\n", Random());
  1232. }
  1233.  
  1234. The situation I was referring to (sorry for not making this clear
  1235. in my first post) is illustrated by the following code:
  1236.  
  1237. #include <stdio.h>
  1238. #include <useful.h>  // my homebrew library of useful routines
  1239.                      // such as InitAll()
  1240. main()
  1241. {
  1242.   long dummy;
  1243.   
  1244.   InitAll();         // calls InitGraf, InitWindows, etc.
  1245.   printf("%ld\n");
  1246.   GetDateTime(&dummy);
  1247.   randSeed = dummy;
  1248.   printf("%ld\n", Random());
  1249. }
  1250.  
  1251. This code, compiled under Think C 5, generates a different
  1252. random number every time it is run.
  1253.  
  1254. +------------------------------------+
  1255. | Mark Nutter                        |
  1256. | manutter@grove.iup.edu             |
  1257. +------------------------------------+
  1258. | Apple Support Manager              |
  1259. | Indiana University of Pennsylvania |
  1260. | G-4 Stright, Indiana, PA 15705     |
  1261. +------------------------------------+
  1262. | Bonus question:  Which of these    |
  1263. |   two statements is correct?       |
  1264. |     A) Statement "B" is false.     |
  1265. |     B) Statement "A" is true.      |
  1266. +------------------------------------+
  1267.  
  1268. ---------------------------
  1269.  
  1270. End of C.S.M.P. Digest
  1271. **********************
  1272.